package com.aoxin.controller.opm;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.opm.SlfSyllabusDate;
import com.aoxin.service.inter.opm.SyllabusDateService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

/**
 * 课程时间安排Controller
 * 
 * @author Melody
 * @date 2018年3月22日 上午9:53:24
 */
@Controller
@ResponseBody
@RequestMapping("/web/syllabusDate")
public class SyllabusDateController {

	@Autowired
	private SyllabusDateService syllabusDateService;

	/**
	 * 添加课程时间安排
	 * 
	 * @param syllabusDate
	 *            课程时间安排
	 */
	@RequestMapping("/insertSyllabusDate")
	@LogInfo(content = "课程时间安排", operateType = OperateType.INSERT)
	public AjaxRes insertSyllabusDate(SlfSyllabusDate syllabusDate, AjaxRes ajaxRes) {
		try {
			this.syllabusDateService.insertSlfSyllabusDate(syllabusDate);
			ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 修改课程时间安排
	 * 
	 * @param syllabusDate
	 *            课程时间安排
	 */
	@RequestMapping("/updateSyllabusDate")
	@LogInfo(content = "课程时间安排", operateType = OperateType.UPDATE)
	public AjaxRes updateSyllabusDate(SlfSyllabusDate syllabusDate, AjaxRes ajaxRes) {
		try {
			this.syllabusDateService.updateSlfSyllabusDate(syllabusDate);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 批量修改课程时间安排状态
	 * 
	 * @param syllabusDateIds
	 *            课程时间安排ID集合
	 * @param state
	 *            状态
	 */
	@RequestMapping("/updateSyllabusDateStates")
	@LogInfo(content = "课程时间安排", operateType = OperateType.UPDATE)
	public AjaxRes updateSyllabusDateStates(@RequestParam("syllabusDateIds") List<Integer> syllabusDateIds, @RequestParam("state") Integer state, AjaxRes ajaxRes) {
		try {
			this.syllabusDateService.updateSlfSyllabusDateStates(syllabusDateIds, state);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 批量删除课程时间安排
	 * 
	 * @param syllabusDateIds
	 *            课程时间安排ID集合
	 */
	@RequestMapping("/deleteSlfSyllabusDateByIds")
	@LogInfo(content = "课程时间安排", operateType = OperateType.DELETE)
	public AjaxRes deleteSlfSyllabusDateByIds(@RequestParam("syllabusDateIds") List<Integer> syllabusDateIds, AjaxRes ajaxRes) {
		try {
			this.syllabusDateService.deleteSlfSyllabusDateByIds(syllabusDateIds);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 查询课程时间安排
	 * 
	 * @param map
	 *            条件集合
	 */
	@RequestMapping("/getSlfSyllabusDateList")
	@LogInfo(content = "课程时间安排", operateType = OperateType.QUERY)
	public AjaxRes getSlfSyllabusDateList(@RequestParam Map<String, Object> map, AjaxRes ajaxRes) {
		try {
			List<SlfSyllabusDate> slfSyllabusDates = this.syllabusDateService.getSlfSyllabusDateList(map);
			ajaxRes.setSucceed(slfSyllabusDates, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 课程时间安排下拉树
	 */
	@RequestMapping("/getSelectSyllabusDateList")
	public AjaxRes getSelectSyllabusDateList(@RequestParam("classroomId") Integer classroomId, AjaxRes ajaxRes) {
		try {
			List<SlfSyllabusDate> selectDtos = this.syllabusDateService.getSelectList(classroomId);
			ajaxRes.setSucceed(selectDtos, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
